Skip to content

Refactoring 2025#59

Merged
histrio merged 10 commits intocloudlinux:masterfrom
histrio:refactor-2025
Jul 15, 2025
Merged

Refactoring 2025#59
histrio merged 10 commits intocloudlinux:masterfrom
histrio:refactor-2025

Conversation

@histrio
Copy link
Collaborator

@histrio histrio commented Jul 15, 2025

No description provided.

@histrio histrio requested a review from Copilot July 15, 2025 10:18

This comment was marked as outdated.

@histrio histrio requested a review from Copilot July 15, 2025 10:23

This comment was marked as outdated.

@histrio histrio requested a review from Copilot July 15, 2025 10:25

This comment was marked as outdated.

@histrio histrio requested a review from Copilot July 15, 2025 10:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors subprocess calls to support timeouts, centralizes ELF parsing constants, enhances logging, and fixes a typo in distribution parsing.

  • Introduce check_output_with_timeout with signal-based timeout and replace all check_output calls
  • Add constants (ELF_MAGIC_BYTES, PROC_TIMEOUT, MAX_NOTE_SIZE, BYTE_ALIGNMENT), note-size validation, and logging improvements
  • Correct description_version_id key typo and update tests (including Unicode normalization)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
uchecker.py Added timeout wrapper, constants, ELF validation, improved logging and error handling
tests/test_kernelcare.py Updated mocks to use check_output_with_timeout and added Unicode normalize test
Comments suppressed due to low confidence (2)

tests/test_kernelcare.py:22

  • Add dedicated unit tests for check_output_with_timeout to cover normal execution, subprocess errors, and timeout-triggered paths to ensure cleanup of alarms and handlers.
def tests_get_patched_data(mock_system, tmpdir):

uchecker.py:78

  • [nitpick] Expand this docstring to clarify behavior on platforms without SIGALRM (no timeout enforcement) and describe return values on errors or timeouts.
    """Enhanced check_output with timeout support for Python 2/3."""

uchecker.py Outdated
signal.signal(signal.SIGALRM, old_handler)
raise

except (subprocess.SubprocessError, OSError) as e:
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referencing subprocess.SubprocessError may break on Python versions where SubprocessError isn’t defined (e.g., Python 2). Consider using getattr(subprocess, 'SubprocessError', OSError) or catching OSError and subprocess.CalledProcessError instead.

Suggested change
except (subprocess.SubprocessError, OSError) as e:
except (getattr(subprocess, 'SubprocessError', OSError), OSError) as e:

Copilot uses AI. Check for mistakes.
@histrio histrio requested a review from Copilot July 15, 2025 10:50

This comment was marked as outdated.

@histrio histrio requested a review from Copilot July 15, 2025 14:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds timeout support to subprocess calls, replaces magic values with named constants for ELF parsing, and fixes a typo in distribution parsing.

  • Introduces check_output_with_timeout with a default timeout and enhanced exception handling
  • Defines ELF_MAGIC_BYTES, PROC_TIMEOUT, MAX_NOTE_SIZE, and BYTE_ALIGNMENT, replacing inline values in get_build_id
  • Corrects the description_version_id typo in _linux_distribution and updates tests for the new function and Unicode normalization

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
uchecker.py Added constants, implemented check_output_with_timeout, replaced magic values, improved logging formatting, fixed typo in distribution parsing
tests/test_kernelcare.py Updated tests to patch check_output_with_timeout and added test_normalize_unicode
Comments suppressed due to low confidence (2)

tests/test_kernelcare.py:117

  • There are no tests covering check_output_with_timeout, including timeout and error paths. Add unit tests for normal execution, timeouts, non-zero exit codes, and subprocess errors.
def test_normalize_unicode():

uchecker.py:49

  • [nitpick] Consider renaming PROC_TIMEOUT to DEFAULT_PROC_TIMEOUT_SECS or similar for clearer intent that this value is in seconds.
PROC_TIMEOUT = 30

@histrio histrio merged commit 9d4e54a into cloudlinux:master Jul 15, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant